package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    //2：各个状态的订单数量统计
//    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);
    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
    /**
     * 根据id查询订单
     * @param id
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);


    // 3：查询超时的订单
    @Select("select * from orders where status = #{status} and order_time = #{time}")
    List<Orders> getStatusAndTimeoutOrders(Integer status , LocalDateTime time);

    //查询数据库返回每一天的营业额
//    @Select("select sum(amount) from sky_take_out.orders where status = #{map.get} and order_time >= #{beginTime} and order_time <= #{endTime}")
    Double SumByMap(Map map);

    //获取完成订单的数量
    Integer NumberByMap(Map map);

    //获取销量排名
    List<GoodsSalesDTO> getNameAndNumber(Map map);
}
